package com.xbs.controller.user;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.entity.UserEntity;
import com.xbs.service.user.MessageService;
@WebServlet("/userview/myCenter/message")
public class MyCenter_message extends BaseServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String uname = (String) req.getSession().getAttribute("uname");
		MessageService messageservice = new MessageService();
		UserEntity message = messageservice.selAll(uname);
		req.setAttribute("message", message);
		forward("userview/myCenter/myCenter_message");
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String uname = (String) req.getSession().getAttribute("uname");
		String oldTelid = req.getParameter("oldTelid");
		String newTelid = req.getParameter("newTelid");
		MessageService messageservice = new MessageService();
		UserEntity str1 = messageservice.selAll(uname);
		String telphone = str1.getUser_telphone();
		req.setAttribute("message", str1);
		if(oldTelid == null || oldTelid.equals("")){
			String str2 = "请输入原手机号！";
			req.setAttribute("telphone1", str2);
		}else if(telphone.equals(oldTelid)){
			if(newTelid == null || newTelid.equals("")){
				String str3 = "请确认新手机号！";
				req.setAttribute("telphone2", str3);
			}else{
				messageservice.updateTel(newTelid, telphone);
				String str4 = "修改成功！";
				req.setAttribute("telphone3", str4);
			}
		}else {
			String str5 = "原手机号错误！";
			req.setAttribute("telphone4", str5);
		}
		forward("userview/myCenter/myCenter_message");
	}
}
